const userService = require('../../services/userService');
import Dialog from '../../vant/dialog/dialog';

var app = getApp()
Page({
  data: {
      assets:app.assets,
      assetsByEnv:app.assetsByEnv,
      value:'',
      list:[]
  },
    onShareAppMessage: function () {
        return {
            imageUrl:this.data.assetsByEnv+'/tanchuang1.png',
            title: '鞋库鉴定',
            path: '/pages/home/home',
            success: function(res) {
            },
            fail: function(res) {
            }
        }
    },
  onShow: function(){

  },
  onLoad: function (options) {
      wx.setNavigationBarTitle({
          title:'鞋库鉴定'
      })
        this._getAppraList();
  },
    onChange(e) {
        this.setData({
            value: e.detail
        });
    },
    onSearch:function(e) {
        this.getByOuterid();
    },
    _getAppraList:function(){
        var user = wx.getStorageSync('user');
        var openid = user.openid;
        var params = {
            customerId:openid,
            outerid:this.data.value
        };
        userService.pageList(params).then((data=>{
            if(data.result) {
            this.setData({
                list:data.obj.list
            });
        }else{
            wx.showToast({title:data.errorMsg,icon:'none'});
        }
    }),(error=>{
            wx.showToast({title:'addAppra接口异常',icon:'none'});
    }));
    },
    goDetail(e) {
        var id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '../appraDetail/appraDetail?id=' + id
        })
    },

    detailRemark(e) {
        Dialog.alert({
            confirmButtonText:'关闭',
            title: '补图原因',
            message: e.target.dataset.remark
        }).then(() => {
            // on close
        });
    },
    getByOuterid:function(){
        var params = {
            outerid:this.data.value
        };
        userService.getByOuterid(params).then((data=>{
            if(data.result) {

            if (data.obj && data.obj.id) {
                wx.navigateTo({
                    url: '../appraDetail/appraDetail?id=' + data.obj.id
                })
            } else {
                wx.navigateTo({
                    url: '../appraDetail/appraDetail'
                })
            }
        }else{
            wx.showToast({title:data.errorMsg,icon:'none'});
        }
    }),(error=>{
            wx.showToast({title:'addAppra接口异常',icon:'none'});
    }));
    },
});
